// pages/mine/mine.js
const appConfig = require('../../config/config.js');
const http = require('../../utils/http.js');
const nav = require('../../utils/navigator.js');
const tip = require('../../utils/tip.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //底部导航栏配置
    //定义一个数组，数组每一项是对象，对象里面对应菜单的数据
    //管理菜单的每一项的不同参数，还有不同布局结构需要的额外的参数
    navData: [{
      name: "寻宠", //文本
      current: 0, //是否是当前页，0不是  1是
      style: 0, //样式
      ico: 'icon-zhonglixunta', //不同图标
      fn: 'gotoNoticeIndex' //对应处理函数
    }, {
      name: "寻主人",
      current: 0,
      style: 0,
      ico: 'icon-xunren',
      fn: 'gotoPickupIndex'
    }, {
      name: "",
      current: 0,
      style: 1,
      ico: '',
      fn: 'gotopublish'
    }, {
      name: "圈子",
      current: 0,
      style: 0,
      ico: 'icon-xunren',
      fn: 'gotoQuanzi',
    }, {
      name: "我的",
      current: 1,
      style: 0,
      ico: 'icon-wode2',
      fn: 'bindViewMy'
    }],
    txtUserName: '',
    txtUserImg: '',
    dianzanliang: '',
    zhuanfaliang: '',
    hiddenModal: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    http.post(appConfig.baseUrl + 'Login/GetUserInfoById', {
      Id: wx.getStorageSync('userId')
    }, function (res) {
      if (res) {
        console.log(res.data);
        that.setData({
          txtUserName: res.data.NickName,
          txtUserImg: res.data.AvatarUrl,
          dianzanliang:res.data.FavoriteCnt,
          zhuanfaliang:res.data.ShareCount
        });
      }
    }, function (res) {

    });
  },

  bindMyNoticeClick: function (e) {
    nav.navigateTo("../mynotice/mynotice?userId=" + wx.getStorageSync('userId'));
  },
  bindMyMessageClick:function(e){
    nav.navigateTo("../mymessage/mymessage?userId=" + wx.getStorageSync('userId'));
  },
  bindMyFavoriteClick:function(e)
  {
    nav.navigateTo("../myfavorite/myfavorite?userId=" + wx.getStorageSync('userId'));
  },
  bindMyshareClick:function(e){
    nav.navigateTo("../myshare/myshare?userId=" + wx.getStorageSync('userId'));
  },
  bindAboutsClick:function(e){
    nav.navigateTo("../abouts/abouts?userId=" + wx.getStorageSync('userId'));
  },
  //发布按钮点击事件
  gotopublish: function (e) {
    this.setData({
      hiddenModal: false
    });
  },
  //模态框关闭按钮点击事件
  modalCloseClick: function (e) {
    this.setData({
      hiddenModal: true
    });
  },
  gotoNoticeIndex: function (e) {
    var that = this;
    wx.reLaunch({ url: '../index/index?noticeType=0' });
    that.setData({
      qyopen: false,
      qyshow: true,
      nzopen: false,
      pxopen: false,
      nzshow: true,
      pxshow: true,
      shownavindex: 0,
      noticeType: 0,
      navData: [{
        name: "寻宠", //文本
        current: 1, //是否是当前页，0不是  1是
        style: 0, //样式
        ico: 'icon-zhonglixunta', //不同图标
        fn: 'gotoNoticeIndex' //对应处理函数
      }, {
        name: "寻主人",
        current: 0,
        style: 0,
        ico: 'icon-xunren',
        fn: 'gotoPickupIndex'
      }, {
        name: "",
        current: 0,
        style: 1,
        ico: '',
        fn: 'gotopublish'
      }, {
        name: "圈子",
        current: 0,
        style: 0,
        ico: 'icon-xunren',
        fn: 'gotoQuanzi',
      }, {
        name: "我的",
        current: 0,
        style: 0,
        ico: 'icon-wode2',
        fn: 'bindViewMy'
      }]
    });
    that.onSearch();
  },
  gotoPickupIndex: function (e) {
    var that = this;
    wx.reLaunch({ url: '../index/index?noticeType=1' });
    that.setData({
      qyopen: false,
      qyshow: true,
      nzopen: false,
      pxopen: false,
      nzshow: true,
      pxshow: true,
      shownavindex: 0,
      noticeType: 1,
      navData: [{
        name: "寻宠", //文本
        current: 0, //是否是当前页，0不是  1是
        style: 0, //样式
        ico: 'icon-zhonglixunta', //不同图标
        fn: 'gotoNoticeIndex' //对应处理函数
      }, {
        name: "寻主人",
        current: 1,
        style: 0,
        ico: 'icon-xunren',
        fn: 'gotoPickupIndex'
      }, {
        name: "",
        current: 0,
        style: 1,
        ico: '',
        fn: 'gotopublish'
      }, {
        name: "圈子",
        current: 0,
        style: 0,
        ico: 'icon-xunren',
        fn: 'gotoQuanzi',
      }, {
        name: "我的",
        current: 0,
        style: 0,
        ico: 'icon-wode2',
        fn: 'bindViewMy'
      }]
    });
    wx.setNavigationBarTitle({
      title: '寻主人'
    });
    that.onSearch();
  },
  gotoQuanzi: function (e) {
    var that = this;
    nav.navigateTo("../quanzi/list/list");

  },
  //发布确认按钮点击事件
  onPublishClick: function(e) {
    console.log(e.target.dataset.noticeTypeId);
    //var noticeType = e.target.dataset.noticeTypeId;
    this.setData({  
      nzopen: false,
      pxopen: false,
      qyopen: false,
      nzshow: true,
      pxshow: false,
      qyshow: true,
      shownavindex: 0,
      hiddenModal: true 
      });
    
    nav.navigateTo('../notice/notice', {
      noticeType: e.target.dataset.noticeTypeId
    });
    
  },
  /**
  * 控制 pop 的打开关闭
  * 该方法作用有2:
  * 1：点击弹窗以外的位置可消失弹窗
  * 2：用到弹出或者关闭弹窗的业务逻辑时都可调用
  */
 toggleDialog() {
  this.setData({
    hiddenModal: !this.data.hiddenModal
  });

},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})